//cd C:\Users\gu_w\Documents 
clear all
set more off
log using DataLog_Q4_job_upto2018, replace

qui use GU04_18_Q_j_all, replace

///macro data
sort yrq
save masterfile, replace

qui use deflators_n_ur_Q4_2018, clear
sort yrq
save usefile, replace

qui use masterfile, clear
merge m:1 yrq using usefile, update replace
sort _merge
drop if _merge<3
drop _merge

//generate variables
qui replace yrq2=yq(year, quarter) //time variable must contain only integer values
qui tsset idj yrq2, quarterly 
qui replace logemplydiff=log(j_employment/l4.j_employment)

//save GU04_18_Q4_j_all, replace

//Make them real:
qui tsset idj yrq2, quarterly 
sort idj yrq2

//CPI all/GNP df
foreach a of varlist j_2 j_nonqf j_legal j_disc j_other aj_2 aj_nonqf aj_legal aj_disc aj_other j_comp j_qfbf j_CQBENC* j_cqtotben j_ahr aj_comp aj_qfbf aj_CQBENC* aj_cqtotben aj_ahr { 
qui replace logdiff`a'=log`a'-l4.log`a'
qui replace logdiffgnpdf`a'=loggnpdf`a'-l4.loggnpdf`a'
}

//Robustness: cpi by region
foreach a of varlist j_2 j_nonqf j_legal j_disc j_other aj_2 aj_nonqf aj_legal aj_disc aj_other j_comp j_qfbf j_CQBENC* j_cqtotben j_ahr aj_comp aj_qfbf aj_CQBENC* aj_cqtotben aj_ahr { 
qui replace logdiffcrg`a'=logcrg`a'-l4.logcrg`a' if rg_ne==1
qui replace logdiffcrg`a'=logcrg`a'-l4.logcrg`a' if rg_mw==1
qui replace logdiffcrg`a'=logcrg`a'-l4.logcrg`a' if rg_w==1
qui replace logdiffcrg`a'=logcrg`a'-l4.logcrg`a' if rg_s==1
}

//CPI medical care
foreach a of varlist j_CQBENC11 aj_CQBENC11{ 
qui replace logdiffcmed`a'=logcmed`a'-l4.logcmed`a'
}

//Robustness: ppi
foreach a of varlist j_2 j_nonqf j_legal j_disc j_other aj_2 aj_nonqf aj_legal aj_disc aj_other j_comp j_qfbf j_CQBENC* j_cqtotben j_ahr aj_comp aj_qfbf aj_CQBENC* aj_cqtotben aj_ahr { 
qui replace logdiffppi`a'=logppi`a'-l4.logppi`a'
}

//Robustness: ppi manufacturing
foreach a of varlist j_2 j_nonqf j_legal j_disc j_other aj_2 aj_nonqf aj_legal aj_disc aj_other j_comp j_qfbf j_CQBENC* j_cqtotben j_ahr aj_comp aj_qfbf aj_CQBENC* aj_cqtotben aj_ahr { 
qui replace logdiffppim`a'=logppim`a'-l4.logppim`a' if n1==3
}

save GU04_18_Q4_j_all, replace
log close
